layui.use(['ax','element', 'admin'], function () {
    var $ = layui.jquery;
    var element = layui.element;
    var $ax = layui.ax;
    var admin = layui.admin;

    // 加载更多按钮点击事件
    $('#btn-more1').click(function () {
        var $that = $(this);
        var str = $that.prev()[0].outerHTML;
        for (var i = 0; i < 5; i++) {
            $that.before(str);
        }
    });

    // 清空消息点击事件
    $('.message-btn-clear').click(function () {
        $(this).css('display', 'none');
        $(this).prev().find('.message-list-item').remove();
        $(this).prev().find('.message-btn-more').remove();
        $(this).prev().find('.message-list-empty').css('display', 'block');
    });


    var ajax = new $ax(Feng.ctxPath + "/ticket/getNotice/");
    var result = ajax.start();
    result.noticeList.forEach(function(item,index){
        $("#noNotice").css('display', 'none');
        var orderId=item.orderId
        var orderSource = item.orderSource
        var content = '<a class="message-list-item" onclick="ticketDispatcher('+orderId+','+orderSource+')" href="#">'+
            '<img class="message-item-icon" src='+Feng.ctxPath+'"/assets/common/images/message.png">'+
            '<div class="message-item-right">'+
            '<h2 class="message-item-title">'+item.content+'</h2> ' +
            '<p class="message-item-text">工单编号:'+item.orderNo+'</p> </div> </a>'
        $("#notices").append(content)
        $("#noticeCount").text("通知("+result.noticeCount+")")
    })
    if(result.noticeCount==0){
        $("#noticeCount").text("通知("+result.noticeCount+")")
    }
});
function ticketDispatcher(orderId,orderSource) {
    if(orderSource==1){
        top.layui.jquery("[lay-href='/ticket']").click();
    }else if (orderSource==2){
        top.layui.jquery("[lay-href='/staffTicket']").click();
    }

    top.layui.admin.open({
        type: 2,
        title: '派单',
        area: '520px',
        content: Feng.ctxPath + '/staffTicket/ticket_dispatch?orderId=' + Number(orderId)+'&typeName=待派单',
        end: function () {
            window.location.reload()
            if(orderSource==1){
                top.layui.jquery("[lay-href='/ticket']").click();
            }else if (orderSource==2){
                top.layui.jquery("[lay-href='/staffTicket']").click();
            }
        }
    });

}